//
//  LoginViewController.m
//  NoNameAmazing
//
//  Created by Hero on 17/8/30.
//  Copyright © 2017年 北京执行力科技有限公司. All rights reserved.
//改动

#import "LoginViewController.h"
#import "UIView+HUD.h"
#import "SetUpDomainViewController.h"
#import "BaseTabbarController.h"
#import "ForgetPsdViewController.h"
@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UITextField *psdTF;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UIButton *domainSetBtn;
@property (weak, nonatomic) IBOutlet UIButton *forgetPsdBtn;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    xx是的撒哒哒哒哒哒
    self.nameTF.layer.cornerRadius = 17.5;
    self.nameTF.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
    self.nameTF.placeholder = @"  账号";
    [self.nameTF setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    self.nameTF.layer.borderWidth = 1;
    self.nameTF.layer.borderColor = UIColorFromRGB(0xffffff).CGColor;
    self.nameTF.layer.masksToBounds = YES;
    self.nameTF.textColor = [UIColor whiteColor];
    self.psdTF.layer.cornerRadius = 17.5;
    self.psdTF.layer.masksToBounds = YES;
    self.psdTF.placeholder = @"  密码";
    [self.psdTF setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    self.psdTF.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
    self.psdTF.layer.borderWidth = 1;
    self.psdTF.layer.borderColor = UIColorFromRGB(0xffffff).CGColor;
    [self.psdTF setSecureTextEntry:YES];
    self.psdTF.textColor = [UIColor whiteColor];
    self.loginBtn.layer.cornerRadius = 17.5;
    self.loginBtn.layer.masksToBounds = YES;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (IBAction)loginBtnClick:(UIButton *)sender {
    NSString * BaseUrl = [us objectForKey:kBaseUrL];
    if (BaseUrl.length == 0) {
        [us setValue:@"http://s-learning.imwork.net:18080" forKey:baseUrl];
    }else{
        [us setValue:BaseUrl forKey:baseUrl];
    }
    if (self.nameTF.text.length == 0 ||self.psdTF.text.length == 0) {
        [self.view showHUDWithTitle:@"账号或密码不可为空！！！"];
        return;
    }
    NSDictionary *params = @{@"accountname":self.nameTF.text,@"password":self.psdTF.text};
    [NetWorkManager requestWithType:1 withUrlString:@"/password/applogin.do" withParaments:params withSuccessBlock:^(id object) {
        
        if ([object[@"status"] integerValue ]== 1) {
            [us setValue:object[@"account"][@"roleid"] forKey:kRoleid];
            [us setValue:object[@"account"][@"userid"] forKey:kUserid];
            
            BaseTabbarController *tab = [[BaseTabbarController alloc]init];
            [self.view.window setRootViewController:tab];
        }

    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];

}

- (IBAction)domainBtnClick:(UIButton *)sender {
    SetUpDomainViewController * VC = [[SetUpDomainViewController alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}
- (IBAction)forgetPsdBtn:(UIButton *)sender {
    ForgetPsdViewController *forgetVc =  [[ForgetPsdViewController alloc]initWithNibName:@"ForgetPsdViewController" bundle:nil];
    [self.navigationController pushViewController:forgetVc animated:YES];
}


@end
